﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace TuongLai_Schools
{
    public class cls_DM_ChisoBMI
    {
        public DataTable GetAll_ChisoBMI()
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select ChiSoBMIID,TenChiSoBMI,ChiSoDau,ChiSoCuoi,isChangeable from DM_ChiSoBMI");
            return dataTable;
        }
        public bool Insert(clsDM_ChisoBMI obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@ChiSoBMIID", obj.ChiSoBMIID);
                db.AddParameter("@TenChiSoBMI", obj.TenChiSoBMI);
                db.AddParameter("@ChiSoDau", obj.ChiSoDau);
                db.AddParameter("@ChiSoCuoi", obj.ChiSoCuoi);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("insert into DM_ChiSoBMI(TenChiSoBMI,ChiSoDau,ChiSoCuoi,isChangeable) values(N'" + obj.TenChiSoBMI + "'," + obj.ChiSoDau + ","+ obj.ChiSoCuoi +",'" + obj.isChangeable + "')");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool update(clsDM_ChisoBMI obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@ChiSoBMIID", obj.ChiSoBMIID);
                db.AddParameter("@TenChiSoBMI", obj.TenChiSoBMI);
                db.AddParameter("@ChiSoDau", obj.ChiSoDau);
                db.AddParameter("@ChiSoCuoi", obj.ChiSoCuoi);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("update DM_ChiSoBMI set TenChiSoBMI=N'" + obj.TenChiSoBMI + "',ChiSoDau=" + obj.ChiSoDau + ",ChiSoCuoi="+ obj.ChiSoCuoi +",isChangeable='" + obj.isChangeable + "' where ChiSoBMIID='" + obj.ChiSoBMIID + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool delete(int ChisoBMIID)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@ChiSoBMIID", ChisoBMIID);
                db.ExecuteNonQuery("delete DM_ChiSoBMI where ChiSoBMIID=" + ChisoBMIID + "");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
